﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using Tools;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class ManageLoginDAL
    {
        public static List<Admin> AdminData()
        {
            string str = "select*from Admin";
            SqlDataReader sdr = Tools.DBHelper.ExecuteQuery(str);
            List<Admin> adminData = new List<Admin>();
            while (sdr.Read())
            {
                Admin admin = new Admin();
                admin.ID = (int)sdr["AdminID"];
                admin.AdminName = (string)sdr["AdminName"];
                admin.AdminPwd = (string)sdr["AdminPwd"];
                adminData.Add(admin);
            }
            sdr.Close();
            return adminData;
        }
        public static List<Permission> PermissionList(int AdminID)
        {
            string str = "select * from Permission where PermissionID in(select PermissionID from PermissionGroup where TypeID=(select TypeID from Admin where AdminID="+AdminID+"))";
            SqlDataReader sdr = Tools.DBHelper.ExecuteQuery(str);
            List<Permission> PermissionList = new List<Permission>();
            while (sdr.Read())
            {
                Permission Permission1 = new Permission();
                Permission1.PermissionID = (int)sdr["PermissionID"];
                Permission1.PermissionName = (string)sdr["PermissionName"];
                Permission1.PermissionHref = (string)sdr["PermissionHref"];
                Permission1.PermissionDesc = (string)sdr["PermissionDesc"];
                Permission1.PermissionStatus = (int)sdr["PermissionStatus"];
                Permission1.GroupUp = (int)sdr["GroupUp"];
                PermissionList.Add(Permission1);
            }
            sdr.Close();
            return PermissionList;
        }
    }
}
